package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	@GetMapping("getBaseCategoryList")
	public Result getBaseCategoryList(){
		List<JSONObject> categories=this.baseCategoryService.getBaseCategoryList();
		return Result.ok(categories);
	}
	@Operation(summary = "根据一级分类Id 查询分类属性数据")
	@GetMapping("findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttribute(@PathVariable Long category1Id){
			//调用服务层方法
		return Result.ok(baseCategoryService.findAttributeByCategory1Id(category1Id));
	}
	@GetMapping("queryCategoryView/{category3Id}")
	public Result<BaseCategoryView> queryCategoryView(@PathVariable Long category3Id) {
		BaseCategoryView baseCategoryView =this.baseCategoryService.queryCategoryView(category3Id);
		try {
			Thread.sleep(20);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
		return Result.ok(baseCategoryView);
	}
	//findTopBaseCategory3/10
	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> baseCategory3s=this.baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3s);
	}
	//getBaseCategoryList/11
	@GetMapping("getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject jsonObject=this.baseCategoryService.getBaseCategory(category1Id);
		return Result.ok(jsonObject);
	}
}

